package cn.iocoder.yudao.module.promotion.api.coupon;


import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.*;
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO;
import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper;
import cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
import cn.iocoder.yudao.module.promotion.service.coupon.CouponTemplateService;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * 优惠劵模板 API 实现类
 *
 * @author 万民匠心
 */
@Service
@Validated
public class CouponTemplateApiImpl implements CouponTemplateApi {

    @Resource
    private CouponTemplateService couponService;
    @Resource
    private CouponTemplateMapper couponTemplateMapper;

    @Override
    public List<CouponTemplateRespDTO> getCouponTemplateList(Collection<Long> ids) {
        if (CollUtil.isEmpty(ids)) {
            return Lists.newArrayList();
        }
        List<CouponTemplateDO> couponTemplateList = couponService.getCouponTemplateList(ids);
        return BeanUtils.toBean(couponTemplateList, CouponTemplateRespDTO.class);
    }

    @Override
    public List<CouponTemplateRespDTO> getCouponTemplateList(CouponTemplateReqDTO reqDTO) {
        List<CouponTemplateDO> couponTemplateList = couponTemplateMapper.selectList(reqDTO);
        return BeanUtils.toBean(couponTemplateList, CouponTemplateRespDTO.class);
    }
}
